<template>
    <div v-loading="loading">
        <el-card :body-style="{ height: 'auto', padding: '0px' }">
            <div v-for="val in list"  :key="val.p_id" >
                <div class="listBox" @click="handleJump(val)">
                    <img v-bind:src='val.avatar' class="image"/>
                    <p class="factoryName">{{val.company}}</p>
                </div>
            </div>
        </el-card>

        <div class="factoryPage">
            <el-pagination
                    v-if="pageVisible"
                    background
                    layout="prev, pager, next"
                    :page-size="8"
                    :total="total"
                    @current-change="handlePage"
            >
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        name: 'factorList',
        data(){
            return{
                list:[],
                loading: false,
                total: 0,
                pageVisible: true
            }
        },
        methods:{
            defaultData(page){
                this.loading = true;
                this.$http.get('/agent/mill/apply/mill',{
                    params:{
                        token: localStorage.getItem('user_token'),
                        page: page,
                        pageSize: 8,
                        id: localStorage.getItem('user_id')
                    }
                }).then((response=> {
                    if (response.data.status === 'success'){
                        this.list = response.data.data.list;
                        this.total = response.data.data.pagination.total;

                        if(response.data.data.pagination.total <= 8 ){
                            this.pageVisible = false
                        }
                    }
                    this.loading = false;
                })).catch((error => {
                    console.log(error);
                    this.loading = false;
                }))
            },

            handleJump(value){
                this.$router.push({name: 'factoryGoodsList', query:{
                        p_id: value.p_id,
                        mill_id: value.mill_id,
                    }});
            },

            handlePage(page){
                this.defaultData(page);
            }
        },
        mounted() {
            this.defaultData();
        }
    }
</script>

<style>
    .factoryName{
        text-align: center;
        float: left;
        width: 100%;
        height: 20px;
        color: #303133;
        font-family: "Helvetica Neue",
        Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", SimSun, sans-serif;
        font-weight: 400;
    }

    .image {
        height: 300px;
        border-radius: 8px;
        float: left;
        width: 300px;
        display: block;
    }

    .listBox{
        height: 350px;
        width: 300px;
        border-radius: 8px;
        box-shadow: 2px 4px 6px #cdcdcd;
        float: left;
        margin-left: 70px;
        margin-top: 24px;
        margin-bottom: 24px;
        cursor: pointer;
    }

    .factoryPage{
        margin-top: 24px;
        text-align: center;
    }
</style>